package com.example.qxfw.hbqx.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.qxfw.common.entity.qx.ImportantWeather;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
@DS("qx")
public interface ImportantWeatherMapper extends BaseMapper<ImportantWeather> {
    /**
     * 根据站点名字和天气类型查询观测时间
     * @param weathertype 天气类型
     * @param stationname 站点名字
     * @return
     */
    @Select("SELECT observetime " +
            "FROM important_weather " +
            "WHERE weathertype=#{weathertype} AND stationname LIKE concat('%',#{stationname},'%') " +
            "ORDER BY observetime DESC " +
            "LIMIT 1 ")
    List<ImportantWeather> selectByWeatherTypeAndStationNameOfImportantWeather(String weathertype, String stationname);

    /**
     * 根据天气类型，站点名字和观测时间段查询信息
     * @param observetimeStart 观测时间起点
     * @param observetimeEnd 观测时间终点
     * @param weathertype 天气类型
     * @param stationname 站点名字
     * @return
     */
    @Select("SELECT stationid, stationname, observetime, weathertype, weatherdetail, lon, lat " +
            "FROM important_weather " +
            "WHERE observetime BETWEEN #{observetimeStart} AND #{observetimeEnd} " +
            "AND weathertype = #{weathertype} " +
            "AND stationname LIKE concat('%',#{stationname}.'%') " +
            "ORDER BY observetime DESC ")
    List<ImportantWeather> selectByWeatherTypeAndStationNameAndObservetimeOfImportantWeather(Date observetimeStart, Date observetimeEnd, String weathertype, String stationname);





}
